package com.ftg.elvis.controller;

import com.ftg.elvis.pojo.Brand;
import com.ftg.elvis.service.AdminBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/brand")
public class AdminBrandController {

	@Autowired
	AdminBrandService adminBrandService;

	@GetMapping("/showAll")
	public Map<String, Object> showAll(int page, int limit, String bname){
		List<Brand> list =  adminBrandService.showAll(page, limit, bname);
		Map<String, Object> map = new HashMap<>();
		map.put("bname", bname);
		map.put("code", 0);
		map.put("count", adminBrandService.getCount(bname));
		map.put("data", list);
		return map;
	}

	@PostMapping("/update")
	public int updateBrand(Brand brand){
		return adminBrandService.updateBrand(brand);
	}

	@DeleteMapping("/del/{bid}")
	public int delete(@PathVariable String bid){
		return adminBrandService.delete(bid);
	}
}
